package com.novellotus.iov.carvice.adapter;

import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentStatePagerAdapter;
import android.support.v4.view.PagerAdapter;

import com.novellotus.iov.carvice.fragment.BaseCarFragment;

import java.util.List;

/**
 * Created by Rich on 2017/7/18.
 */

public class CarFragmentAdapter extends FragmentStatePagerAdapter {

    private List<BaseCarFragment> fragmentList;
    private FragmentManager fm;

    public CarFragmentAdapter(FragmentManager fm, List<BaseCarFragment> fragmentList) {
        super(fm);
        this.fragmentList = fragmentList;
        this.fm = fm;
    }

    @Override
    public Fragment getItem(int position) {
        return fragmentList.get(position);
    }


    @Override
    public int getCount() {
        return fragmentList.size();
    }

    @Override
    public int getItemPosition(Object object) {
        return PagerAdapter.POSITION_NONE;
    }

    public void setFragments(List<BaseCarFragment> fragmentList) {
        this.fragmentList = fragmentList;
        notifyDataSetChanged();
    }

    public void removeFragment(int i) {
        fm.beginTransaction().remove(fragmentList.get(i)).commit();
        fragmentList.remove(i);
    }
}
